/*
 * @Author: hcluo
 * @Date: 2020-04-16 13:53:56
 * @LastEditors: hcluo
 * @LastEditTime: 2020-04-26 17:00:04
 * @Description: 政府项目
 */
import { App } from '../features/home';
import { PageNotFound } from '../features/common';
import homeRoute from '../features/home/route';
import commonRoute from '../features/common/route';
import examplesRoute from '../features/examples/route';
import _ from 'lodash';
import layoutRoute from '../features/layout/route';
import generalRoute from '../features/general/route';
import regionalEconomyRoute from '../features/regional-economy/route';
import specialDataRoute from '../features/special-data/route';
import myRoute from '../features/my/route';
import adminRoute from '../features/admin/route';
import dataAssistantRoute from '../features/data-assistant/route';
import carbonEmissionRoute from '../features/carbon-emission/route';
import componentRoute from '../features/component/route';
import dataRoute from '../features/data/route';

// NOTE: DO NOT CHANGE the 'childRoutes' name and the declaration pattern.
// This is used for Rekit cmds to register routes config for new features, and remove config when remove features, etc.
const childRoutes = [
	carbonEmissionRoute,
	homeRoute,
	commonRoute,
	examplesRoute,
	layoutRoute,
	generalRoute,
	regionalEconomyRoute,
	specialDataRoute,
	myRoute,
	adminRoute,
	dataAssistantRoute,
	componentRoute,
  dataRoute,
];

const routes = [
	{
		path: '/',
		component: App,
		childRoutes: [
			...childRoutes,
			{ path: '*', name: 'Page not found', component: PageNotFound },
		].filter(r => r.component || (r.childRoutes && r.childRoutes.length > 0)),
	},
	// {
	//   path: '/qq',
	//   component: App,
	//   childRoutes: [
	//     ...childRoutes,
	//     { path: '*', name: 'Page not found', component: PageNotFound },
	//   ].filter(r => r.component || (r.childRoutes && r.childRoutes.length > 0)),
	// }
];

// Handle isIndex property of route config:
//  Dupicate it and put it as the first route rule.
function handleIndexRoute(route) {
	if (!route.childRoutes || !route.childRoutes.length) {
		return;
	}

	const indexRoute = _.find(route.childRoutes, (child => child.isIndex));
	if (indexRoute) {
		const first = { ...indexRoute };
		first.path = '';
		first.exact = true;
		first.autoIndexRoute = true; // mark it so that the simple nav won't show it.
		route.childRoutes.unshift(first);
	}
	route.childRoutes.forEach(handleIndexRoute);
}

routes.forEach(handleIndexRoute);
export default routes;
